// fenxiao/index/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    lists:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.GetDistributorInfo();
  },
  //获取分销商信息，如果分销商不存在，则创建新的
  GetDistributorInfo: function () {
    var that = this;
    var disId = wx.getStorageSync('disid')
    var agentId = wx.getStorageSync('agentid')
    if (disId == "" || disId == null){
        disId = 0
    }
    if (agentId == "" || agentId == null) {
        agentId = 0
    }
    wx.request({
      url: app.globalData.host + '/api/Distributor/GetDistributorAndCreate',
      data: {
        userId: app.globalData.userInfo.Uid,
        disId: disId,
        agentId: agentId,
        storeId: app.globalData.storeId,
        weappid: app.globalData.weappid
      },
      success: function (res) {
        console.log("获取分销商信息");
        console.log(res);
        if (res.data.Code == 0) {
          var list = res.data.Data
          console.log(list);
          that.setData({
            lists: list,
          })
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.Message,
            showCancel: false
          })
        }
      }
    })
  },
  toTixian:function(){//提现
    wx.navigateTo({
      url: '/fenxiao/tixian/index?money=' + this.data.lists.AccountBalance,
    })
  },
  toCode:function () {//二维码
    wx.navigateTo({
      url: '/fenxiao/shareCodes/index?userid=' + app.globalData.userInfo.Uid,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.GetDistributorInfo();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})